package tw.zld369504.testmediaplayer;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MainActivity extends AppCompatActivity {

    private final Class[] classes = new Class[]{PLDroidPlayerActivity.class, CustomPlayerActivity.class,PLVideoTextureActivity.class};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ((ListView) findViewById(R.id.listView)).setAdapter(new SimpleAdapter(this, getListData(), android.R.layout.simple_list_item_1, new String[]{"text"}, new int[]{android.R.id.text1}));
        ((ListView) findViewById(R.id.listView)).setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                startActivity(new Intent(MainActivity.this, classes[position]));
            }
        });
    }

    private List<Map<String, Object>> getListData() {
        List<Map<String, Object>> list = new ArrayList<>();
        final String[] s = new String[]{"PLDroid播放器", "自定义播放器","Demo播放器"};
        for (int i = 0; i < classes.length; i++) {
            Map<String, Object> map = new HashMap<>();
            map.put("text", s[i]);
            list.add(map);
        }
        return list;
    }

}
